<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Generate a cut-grid graph for the ICM 2006 talk example</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/graph_laplacian/html/cut_grid_data.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Generate a cut-grid graph for the ICM 2006 talk example</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="keyword">function</span> [A,xy]= cut_grid_data

<span class="comment">% The graph has 64 nodes and 95 edges</span>
<span class="comment">% A is an n x m incidence matrix (n is number of nodes, m is number of edges)</span>
<span class="comment">% xy is the location data</span>
<span class="comment">%</span>
<span class="comment">% Original code by Arpita Ghosh, modified for ICM06 talk by Almir Mutapcic</span>

n  = 8;
r1 = 2;
y  = ones(n,1) * [1:n];
x  = y';
x  = x(:);
y  = y(:);
dx = x * ones(1,n^2);
dy = y * ones(1,n^2);
xy = [ x, y ];

<span class="comment">% Find the adjacency matrix, manually deleting edges to get down to size</span>
Adj1 = tril( ( dx - dx' ) .^ 2 + ( dy - dy' ) .^2 &lt; r1, -1 );
Adj1(49,41) = 0;
Adj1(50,42) = 0;
Adj1(16,8)  = 0;
Adj1(24,16) = 0;
Adj1(15,7)  = 0;
Adj1(23,15) = 0;
Adj1(10,1)  = 0;
Adj1(21,13) = 0;
Adj1(13,5)  = 0;
Adj1(22,14) = 0;
Adj1(14,6)  = 0;
Adj1(51,43) = 0;
Adj1(52,44) = 0;
Adj1(53,45) = 0;
Adj1(54,46) = 0;
Adj1(42,41) = 0;
Adj1(34,33) = 0;
Adj1(26,25) = 0;

<span class="comment">% Build the incidence matrix</span>
[i,j,v] = find(Adj1);
m = length(i);
A = sparse( [i;j], [1:m,1:m]', [ones(m,1);-ones(m,1)] );
</pre>
</div>
</body>
</html>